<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:include href="../admin.xsl" />
	<xsl:include href="../cp/path.xsl" />
	<xsl:include href="../../../xsl/banners/show.xsl" />
	
	<xsl:param name="pTypes" select="/data/response/ptypes" />
	<xsl:param name="positions" select="/data/response/positions" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/admin/banners.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/admin/dialogForms.css" type="text/css" media="all" />
			<script type="text/javascript" src="http://localhost/js/admin/forms.js"></script>
			<script type="text/javascript" src="http://localhost/js/admin/banners.js"></script>
		</head>
		<body>
			<xsl:call-template name="admin-header" />
						
			<div id="blocks">
				<div id="blocks_inner" />
			</div>
			
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response">
		<xsl:param name="cnt" select="count(object)" />
		
		<div id="path">
			<xsl:apply-templates select="document('xmodule://cp/getPath/0;banners')/data/response" mode="cp-path" />
		</div>
		
		<h1>Баннеры</h1>
		
		<div id="banners_worktable">
		
			<div id="banners_worktable_right">
				<h2>Позиции баннеров на странице</h2>
				
				<p>
					<a href="{$baseURI}/admin/banners" onclick="createPosition(); return false;" class="add">Новая позиция</a>
				</p>
				
				<div id="banners_positions">
					<img src="{$baseURI}/images/admin/ajax-loader.gif" />
				</div>
				
				<br />
				
				<h2>Типы страниц</h2>
				
				<p>
					<a href="{$baseURI}/admin/banners" onclick="createType(); return false;" class="add">Новый тип</a>
				</p>
				
				<div id="pages_types">
					<img src="{$baseURI}/images/admin/ajax-loader.gif" />
				</div>
			</div>
		
			<div id="banners_worktable_left">
				<h2>Список баннеров</h2>
				
				<xsl:apply-templates select="message" />
				
				<p>
					<a href="{$baseURI}/admin/banners/add_banner" class="add">Создать новый баннер</a>
				</p>
				
				<xsl:if test="$cnt = 0">
					<p>Ни одного баннера не создано</p>
				</xsl:if>
				<xsl:if test="$cnt != 0">
					<table class="standart" cellspacing="0" cellpadding="0">
						<tbody>
							<tr>
								<th>Имя</th>
								<th>Активен</th>
								<th>Страницы</th>
								<th>Позиция</th>
								<th>Вес</th>
								<th>Опции</th>
							</tr>
							
							<xsl:apply-templates select="object[@type='banner']" />
						</tbody>
					</table>
				</xsl:if>
			</div>
		</div>
		
		<script type="text/javascript">
			bannersWorktable ();
		</script>
	</xsl:template>
	
	<xsl:template match="object[@type='banner']">
		<xsl:param name="position" select="property[@name='position']/value" />
		<xsl:param name="cntPagesTypes" select="count(property[@name='pages']/value)" />
		
		<tr>
			<td>
				<a href="{$baseURI}/admin/banners/edit_banner/{@id}" class="mainlink" title="Редактировать">
					<xsl:value-of select="property[@name='title']/value" />
				</a>
			</td>
			<td style="text-align:center;">
				<xsl:choose>
					<xsl:when test="property[@name='active']/value='1'">
					<img src="{$baseURI}/images/admin/on.png" />
					</xsl:when>
					<xsl:otherwise>
						<img src="{$baseURI}/images/admin/off.png" />
					</xsl:otherwise>
				</xsl:choose>
			</td>
			<td>
				<xsl:for-each select="property[@name='pages']/value">
					<xsl:call-template name="page-type">
						<xsl:with-param name="val" select="." />
					</xsl:call-template>
					
					<xsl:if test="position() != $cntPagesTypes">
						<xsl:text>,</xsl:text>
					</xsl:if>
					<br />
				</xsl:for-each>
			</td>
			<td>
				<xsl:value-of select="$positions/position[@id=$position]" />
			</td>
			<td>
				<xsl:value-of select="property[@name='weight']/value" />
			</td>
			<td>
				<a href="{$baseURI}/admin/banners/delete_banner/{@id}?scode={$scode}" onclick="if(!confirm('Вы действительно хотите удалить этот баннер?'))return false;">удалить</a>
			</td>
		</tr>
	</xsl:template>
	
	<xsl:template name="page-type">
		<xsl:param name="val" />
		<xsl:value-of select="$pTypes/type[@id=$val]" />
	</xsl:template>
	
</xsl:stylesheet>